package com.situ.domain;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;

public class ImportBillModel implements Comparable<ImportBillModel>, Serializable{
    /** serialVersionUID*/  
    private static final long serialVersionUID = 14545465L;
    
    private int id;                 // 序号
    private String[] names = {};    // 水果名称
    private double[] costPrices;    // 成本价
    private double[] comeIns;       // 进货量
    private double[] comeInCosts;   // 单种水果进货费用
    private double comeInCost;      // 共计花费
    private Date date = new Date(); // 进货日期
    
    private static int numId = 1;
    

    @Override
    public int compareTo(ImportBillModel o) {
        return this.id - o.getId();
    }
    
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        long temp;
        temp = Double.doubleToLongBits(comeInCost);
        result = prime * result + (int) (temp ^ (temp >>> 32));
        result = prime * result + Arrays.hashCode(comeInCosts);
        result = prime * result + Arrays.hashCode(comeIns);
        result = prime * result + Arrays.hashCode(costPrices);
        result = prime * result + ((date == null) ? 0 : date.hashCode());
        result = prime * result + id;
        result = prime * result + Arrays.hashCode(names);
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        ImportBillModel other = (ImportBillModel) obj;
        if (Double.doubleToLongBits(comeInCost) != Double.doubleToLongBits(other.comeInCost))
            return false;
        if (!Arrays.equals(comeInCosts, other.comeInCosts))
            return false;
        if (!Arrays.equals(comeIns, other.comeIns))
            return false;
        if (!Arrays.equals(costPrices, other.costPrices))
            return false;
        if (date == null) {
            if (other.date != null)
                return false;
        } else if (!date.equals(other.date))
            return false;
        if (id != other.id)
            return false;
        if (!Arrays.equals(names, other.names))
            return false;
        return true;
    }

    public ImportBillModel() {
        super();
        this.id = numId++;
    }

    public ImportBillModel(String[] names, double[] costPrices, double[] comeIns) {
        this();
        this.names = names;
        this.costPrices = costPrices;
        this.comeIns = comeIns;
        double[] comeInCosts = new double[names.length];
        double comeInCost = 0.0;
        for (int i = 0; i < names.length; i++) {
            comeInCosts[i] = costPrices[i] * comeIns[i];
            comeInCost += comeInCosts[i];
        }
        this.comeInCosts = comeInCosts;
        this.comeInCost = comeInCost;
        this.date = new Date();
    }

    public ImportBillModel(String[] names, double[] costPrices, double[] comeIns, double[] comeInCosts,
            double comeInCost, Date date) {
        this();
        this.names = names;
        this.costPrices = costPrices;
        this.comeIns = comeIns;
        this.comeInCosts = comeInCosts;
        this.comeInCost = comeInCost;
        this.date = date;
    }

    // getter setter
    public int getId() {
        return id;
    }

//    public void setId(int id) {
//        this.id = id;
//    }

    public String[] getNames() {
        return names;
    }

    public void setNames(String[] names) {
        this.names = names;
    }

    public double[] getCostPrices() {
        return costPrices;
    }

    public void setCostPrices(double[] costPrices) {
        this.costPrices = costPrices;
    }

    public double[] getComeIns() {
        return comeIns;
    }

    public void setComeIns(double[] comeIns) {
        this.comeIns = comeIns;
    }

    public double[] getComeInCosts() {
        return comeInCosts;
    }

    public void setComeInCosts(double[] comeInCosts) {
        this.comeInCosts = comeInCosts;
    }

    public double getComeInCost() {
        return comeInCost;
    }

    public void setComeInCost(double comeInCost) {
        this.comeInCost = comeInCost;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }
    
    
}
